<?php

namespace App\Jobs;

use App\Models\Info;
use App\Models\Order;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\DB;

class OrderReceivedInfo implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $order;

    public function __construct(Order $order)
    {
        $this->order = $order;
    }

    public function handle()
    {
        $provider = $this->order->providerUser;
        $receiver = $this->order->receiverUser;

        $provider_info = ['type'=>Info::INFO_TYPE_ORDER,'content'=>'您的订单已经被:'.$receiver->name."接收"
        ,'owner'=>$provider->id];
        $receiver_info = ['type'=>Info::INFO_TYPE_ORDER,'content'=>'您已经成功接取:'.$provider->name."的订单"
            ,'owner'=>$provider->id];

        $infos = [$provider_info,$receiver_info];
        Info::CreateInfoModel($infos);

    }
}
